package com.zzk.lanouhn.myapplication1.adapters;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;
import com.zzk.lanouhn.myapplication1.R;
import com.zzk.lanouhn.myapplication1.activity.AuthorsActivity;
import com.zzk.lanouhn.myapplication1.activity.ShowKindsDetailsActivity;
import com.zzk.lanouhn.myapplication1.modles.SingleGoodDetails;

/**
 * 单品详情页面用户晒单适配器
 * Created by lanouhn on 16/9/12.
 */
public class SingleGoodShowAdapter extends RecyclerView.Adapter<SingleGoodShowAdapter.userShowViewHolder> {
    private Context context;
    private SingleGoodDetails singleGoodDetails;

    public SingleGoodShowAdapter(Context context, SingleGoodDetails singleGoodDetails) {
        this.context = context;
        this.singleGoodDetails = singleGoodDetails;
    }

    @Override
    public userShowViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_show_singlegood, null);
        userShowViewHolder holder = new userShowViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(userShowViewHolder holder, int position) {
        final SingleGoodDetails.DataBean.PostListBean bean = singleGoodDetails.getData().getPost_list().get(position);
        Picasso.with(context).load(bean.getUser().getAvatar()).into(holder.iv_icon);
        Picasso.with(context).load(bean.getPics().get(0).getUrl()).into(holder.iv_showPic);
        holder.tv_userName.setText(bean.getUser().getNickname());
        holder.tv_show_time.setText(bean.getDatestr());
        holder.tv_userContents.setText(bean.getContent());
        holder.iv_icon.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, AuthorsActivity.class);
                Bundle bundle = new Bundle();
                bundle.putString("authorId", bean.getUser().getUser_id());
                intent.putExtras(bundle);
                context.startActivity(intent);
            }
        });
        holder.tv_userName.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, AuthorsActivity.class);
                Bundle bundle = new Bundle();
                bundle.putString("authorId", bean.getUser().getUser_id());
                intent.putExtras(bundle);
                context.startActivity(intent);
            }
        });
        holder.tv_userContents.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, ShowKindsDetailsActivity.class);
                Bundle bundle = new Bundle();
                bundle.putString("goodsid", bean.getId());
                intent.putExtras(bundle);
                context.startActivity(intent);
            }
        });
        holder.iv_showPic.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, ShowKindsDetailsActivity.class);
                Bundle bundle = new Bundle();
                bundle.putString("goodsid", bean.getId());
                intent.putExtras(bundle);
                context.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return singleGoodDetails.getData().getPost_list().size();
    }


    public class userShowViewHolder extends RecyclerView.ViewHolder {
        private ImageView iv_icon, iv_showPic;
        private TextView tv_userName, tv_userContents, tv_show_time;

        public userShowViewHolder(View itemView) {
            super(itemView);
            iv_icon = (ImageView) itemView.findViewById(R.id.iv_show_user_icon);
            iv_showPic = (ImageView) itemView.findViewById(R.id.iv_show_user_pic);
            tv_userName = (TextView) itemView.findViewById(R.id.tv_show_user_name);
            tv_show_time = (TextView) itemView.findViewById(R.id.tv_show_user_time);
            tv_userContents = (TextView) itemView.findViewById(R.id.tv_show_user_comments);
        }
    }

}
